#include"message.hpp"

int main()
{
//    bitrpc::RPCRequest::ptr rrq = bitrpc::MessageFactory::create<bitrpc::RPCRequest>();
//     Json::Value params;
//     params["num1"]=1;
//     params["num2"]=2;
//     rrq->SetMethod("Add");
//     rrq->SetParams(params);
//     std::string str = rrq->Serialize();
//     std::cout<<str<<std::endl;
//    bitrpc::RPCRequest::ptr rrq2 = bitrpc::MessageFactory::create<bitrpc::RPCRequest>();
//     rrq2->DeSerialize(str);
//     std::cout<<rrq2->method()<<std::endl;
//     Json::Value param;
//     param = rrq2->params();
//     std::cout<<param["num1"].asInt()<<' '<<param["num2"].asInt()<<" "<<std::endl;

    // bitrpc::TopicRequest::ptr trp = bitrpc::MessageFactory::create<bitrpc::TopicRequest>();
    // trp->setTopicKey("news");
    // trp->setTopicOptype(bitrpc::TopicOptype ::TOPIC_PUBLISH);
    // trp->setTopicMsg("shuand");
    //  std::string str = trp->Serialize();
    // std::cout<<str<<std::endl;
    // bitrpc::TopicRequest::ptr trp2 = bitrpc::MessageFactory::create<bitrpc::TopicRequest>();
    // trp2->DeSerialize(str);
    // trp2->check();
    // std::cout<<trp2->TopicKey()<<std::endl;
    // std::cout<<trp2->topicMsg()<<std::endl;
     
    
    // bitrpc::ServiceRequest::ptr trp = bitrpc::MessageFactory::create<bitrpc::ServiceRequest>();
    // trp->setMethod("Add");
    // trp->setServiceOptype(bitrpc::ServiceOptype ::SERVICE_REGISTRY);
    // trp->setHost({"127.0.0.1",8888});
    //  std::string str = trp->Serialize();
    // std::cout<<str<<std::endl;
    // bitrpc::ServiceRequest::ptr trp2 = bitrpc::MessageFactory::create<bitrpc::ServiceRequest>();
    // trp2->DeSerialize(str);
    // trp2->check();
    // std::cout<<trp2->method()<<std::endl;
    // bitrpc::Address addr;
    // addr = trp2->host();
    // std::cout<<addr.first<<' '<<addr.second<<" "<<std::endl;
    

//      bitrpc::RpcResponse::ptr trp = bitrpc::MessageFactory::create<bitrpc::RpcResponse>();
//     trp->setRcode(bitrpc::RCODE::RCODE_OK);
//     trp->setResult(33);
//      std::string str = trp->Serialize();
//     std::cout<<str<<std::endl;
//     bitrpc::RpcResponse::ptr trp2 = bitrpc::MessageFactory::create<bitrpc::RpcResponse>();
//     trp2->DeSerialize(str);
//     trp2->check();
//     std::cout<<(int)trp2->rcode()<<std::endl;
   
//     std::cout<<trp2->result()<<" "<<std::endl;
//     return 0;
// }



// bitrpc::TopicResponse::ptr trp = bitrpc::MessageFactory::create<bitrpc::TopicResponse>();
//     trp->setRcode(bitrpc::RCODE::RCODE_OK);
//      std::string str = trp->Serialize();
//     std::cout<<str<<std::endl;
//     bitrpc::TopicResponse::ptr trp2 = bitrpc::MessageFactory::create<bitrpc::TopicResponse>();
//     trp2->DeSerialize(str);
//     trp2->check();
//     std::cout<<(int)trp2->rcode()<<std::endl;


bitrpc::ServiceResponse::ptr trp = bitrpc::MessageFactory::create<bitrpc::ServiceResponse>();
    trp->setRcode(bitrpc::RCODE::RCODE_OK);
    trp->setMethod("Add");
    trp->setServiceOptype(bitrpc::ServiceOptype::SERVICE_DISCOVERY);
    std::vector<bitrpc::Address> addrs;
    addrs.push_back({"127.0.0.1", 8888});
    addrs.push_back({"127.0.0.2", 8889});
    trp->setHost(addrs);
     std::string str = trp->Serialize();
    std::cout<<str<<std::endl;
    bitrpc::ServiceResponse::ptr trp2 = bitrpc::MessageFactory::create<bitrpc::ServiceResponse>();
    trp2->DeSerialize(str);
    trp2->check();
    std::cout<<(int)trp2->rcode()<<std::endl;
    std::cout<<trp2->method()<<std::endl;
    std::cout<<(int)trp2->serviceOptype()<<std::endl;
    // addrs = trp2->hosts();
    for(auto [a,b]:trp2->hosts())
    {
         std::cout<<a<<' '<<b<<' '<<std::endl;
    }
   
    return 0;
}